package com.member.provider.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.member.dto.ContractManagement;
import com.member.dto.SignQuery;
import com.member.dto.SignResultInform;
import com.member.provider.service.MemberSignService;
import com.member.utils.Result;
import com.member.vo.SignMessageReqVo;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @auther MemberSign
 * @date 2023/12/6 14:13
 * 签约服务
 */
@RestController
@RequestMapping("/provider/sign")
@CrossOrigin
public class MemberSignController {

    @Autowired
    private MemberSignService memberSignService;


    /**
     * @Description TODO
     * @param signResultInform
     * @retuen Result
     * @date 2023/12/18 16:09
     * @auther 银狐先生
     * 签约结果通知
     */
    @PostMapping("/signResultInform")
    public Result signResultInform(SignResultInform signResultInform){
        Result result = memberSignService.signResultInform(signResultInform);
        return result;
    }

    /**
     * @Description TODO
     * @param signResult
     * @retuen Result
     * 查询签约结果
     * @date 2024/1/16 9:10
     * @auther 银狐先生
     */
    @GetMapping("/signSelectResult")
    public Result signSelectResult(SignMessageReqVo signResult){
        SignMessageReqVo signResultDB=memberSignService.signSelectResult(signResult);

        return Result.success(signResultDB);
    }


    /**
     * @Description TODO
     * @param signMessageVo
     * @retuen Result
     * 签约信息查询
     * @date 2024/1/16 16:58
     * @auther 银狐先生 
     */
    @PostMapping("/selectSignMessage")
     public Result selectSignMessage(SignMessageReqVo signMessageVo)  {
        Result result=memberSignService.selectSignMessage(signMessageVo);
        return result;

    }

    /**
     * @Description TODO
     * @param channelId
     * @retuen Result
     * 签约管理列表
     * @date 2024/1/4 13:48
     * @auther 银狐先生
     */
    @GetMapping("/selectSignMessageBySignId")
    public Result selectSignMessageBySignId(String channelId)  {
        Result result=memberSignService.selectSignMessageBySignId( channelId);
        return result;
    }


    /**
     * @Description TODO
     * @param
     * @retuen
     * 签约信息查询[接入方]
     * @date 2024/2/21 11:08
     * @auther 银狐先生
     */
    @PostMapping("/getSignsV2")
    public Result getSignsV2(SignQuery signQueryq)  {
        Result result=memberSignService.getSignsV2(signQueryq);
        return result;
    }



    /**
     * @Description TODO
     * @param
     * @retuen
     * 签约结果通知
     * @date 2024/2/22 9:19
     * @auther 银狐先生
     */
//    @PostMapping("/contractNotification")
//    public Result contractNotification(@RequestBody ContractResult  contractResult)  {
//        Result result=memberSignService.updateContractStatus(contractResult);
//        return result;
//    }



    /**
     * @Description TODO
     * @param
     * @retuen
     * 签约管理
     * @date 2024/3/12 9:51
     * @auther 银狐先生
     */



    @PostMapping("/selectSignByList/{page}/{size}")
    public Result selectAccessList(@PathVariable Integer page,@PathVariable Integer size,@RequestBody ContractManagement contractManagement, @RequestHeader("token") String token
    ){
        //解析token
        Claims claims = Jwts.parser()
                .setSigningKey("xft-ymt")
                .parseClaimsJws(token)
                .getBody();
        LambdaQueryWrapper<ContractManagement> queryWrapper = new LambdaQueryWrapper<>();
        if (contractManagement.getSignStatus()!=null) {
            queryWrapper.eq(ContractManagement::getSignStatus, contractManagement.getSignStatus());
        }
        if (contractManagement.getPaytype()!=null) {
            queryWrapper.eq(ContractManagement::getPaytype, contractManagement.getPaytype());
        }
        if (contractManagement.getContractDate()!=null) {
            queryWrapper.eq(ContractManagement::getContractDate, contractManagement.getContractDate());
        }

        return Result.success(memberSignService.page(new Page<>(page, size), queryWrapper));
    }







}
